/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sg.edu.nus.iss.pacman.form;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;

/**
 *
 * @author Tabiul Mahmood
 */
public class SelectDownloadMazeList extends List implements CommandListener {

	private static final String TITLE = "Select Map to Download";
	private PacManMIDlet mainApp;

	private String[] listMaze;

	private Command cmdSelect;
	private Command cmdBack;

	/**
	 * Constructor for this screen
	 *
	 * @param mainApp PacManMIDlet
	 * @param listRemoteDevices list of remote devices
	 */
	public SelectDownloadMazeList(PacManMIDlet mainApp, String[] listMaze) {
		super(TITLE, List.EXCLUSIVE, listMaze, null);
		this.mainApp = mainApp;
		this.listMaze = listMaze;
        init();
	}

	/**
	 * Initializes the screen
	 */
	private void init() {
		cmdSelect = new Command(PacManMIDlet.LABEL_CMD_SELECT, Command.OK, 1);
		cmdBack = new Command(PacManMIDlet.LABEL_CMD_BACK, Command.EXIT, 1);

		addCommand(cmdSelect);
		addCommand(cmdBack);
		setCommandListener(this);
	}

	/**
	 * This method is used to handle command actions
	 */
	public void commandAction(Command cmd, Displayable disp) {
		if (cmd == cmdBack) {
			mainApp.displayMainMenu();
		} else if (cmd == cmdSelect) {
			int idx = getSelectedIndex();
            mainApp.displayDownloadMazeForm(listMaze[idx]);
			//mainApp.sendChallengeViaBluetooth(idx, listRemoteDevices[idx]);
		}
	}

}
